
try:
    f1 = open(".\\test_file\\test4.txt", "r", encoding= "UTF-8")

except:
    print("出现错误")



# 捕获指定异常
try:
    print(name)
    1/0
# 变量名异常
except NameError as e:
    print("变量未定义异常")
    print(e) # 异常信息

# 捕获多个异常
try:
    # print(name) # 出现异常直接捕获，后面不会运行
    1/0

except (NameError, ZeroDivisionError) as e:
    print(e) # 异常信息